$package('itsm.business');

itsm.business.match=function(){
	this.opt='';
	return {
		//列表
		matchGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'match!findMatchPage.action',
				caption:'成功匹配列表',
				colNames:['ID','买入会员','买入会员姓名','买入会员状态','卖出会员','卖出会员姓名','卖出会员状态','匹配时间','汇款时间','确认收款时间','确认方式','匹配金额','状态',''],
			 	colModel:[
			 	          {name:'id',align:'center'},
			 	          {name:'buyUser',align:'center'},
			 	          {name:'buyUserName',align:'center'},
			 	          {name:'buyUserStatus',align:'center',formatter:itsm.business.match.userStatusForma},
			 	          {name:'sellUser',align:'center'},
			 	          {name:'sellUserName',align:'center'},
			 	          {name:'sellUserStatus',align:'center',formatter:itsm.business.match.userStatusForma},
			 	          {name:'createTime',align:'center',formatter:timeFormatter},
			 	          {name:'messageTime',align:'center',formatter:timeFormatter},
			 	          {name:'closeTime',align:'center',formatter:timeFormatter},
			 	          {name:'confirmType',align:'center'},
			 	          {name:'matchMoney',align:'center'},
			 	          {name:'status',align:'center',formatter:itsm.business.match.statusFormatter},
			 	          {name:'status',align:'center'}
			 	          
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "id"}),
				sortname:'id',
				toolbar:[true,"top"],
				sortorder:'desc',
				pager:'#matchPager'
				});
				$("#matchGrid").jqGrid(params);
				$("#matchGrid").navGrid('#matchPager',navGridParams);
				//列表操作项
				$("#t_matchGrid").css(jqGridTopStyles);
				$("#t_matchGrid").html($('#matchGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#matchGrid","regCenter",10);
		},
		statusFormatter:function(v1,v2,v3){
			if(v1=='0'){
				return "<span style='color:#8A2BE2'>匹配成功</span>";
			}
			if(v1=='1'){
				return "<span style='color:#AB82FF'>已汇款</span>";
			}
			if(v1=='2'){
				return "<span style='color:#228B22;'>交易成功</span>";
			}
			if(v1=='3'){
				return "<span style='color:#CD6090;'>未收到款项</span>";
			}
			if(v1=='4'){
				return "<span style='color:#CD4F39;'>汇款超时</span>";
			}
			if(v1=='5'){
				return "<span style='color:#CD0000;'>收款确认超时</span>";
			}
			if(v1=='6'){
				return "<span style='color:#CD0000;'>已取消</span>";
			}
		},
		userStatusForma:function(v1,v2,v3){
			if(v1=='1'){
				return "<span style='color:red;'>冻结</span>";
			}else{
				return "<span style='color:#228B22;'>正常</span>";
			}
		},
		clean:function(){
			checkBeforeEditGrid('#matchGrid',function(rowData){
				if(rowData.status!='2' && rowData.status!='6'){
					$.messager.confirm('操作提示','是否要取消?',function(r){
						if(r){
							$.post('match!cleanMatch.action','matchId='+rowData.id,function(data){
								alert('取消成功!');
								$('#matchGrid').trigger('reloadGrid');
							});
						}
					});
				}else{
					alert('已结束不允许取消!');
				}
				
			});	
		},
		
		//搜索
		search:function(){
			var sdata=$('#match_search_form').getForm();
			var postData = $("#matchGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'match!findMatchPage.action';
			$('#matchGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		
		
		init:function(){
			itsm.business.match.matchGrid();
		}
	}
	
}();

$(function(){
	itsm.business.match.init();
});